gusucode.com > Neutrosophic logic toolbox Package_ Neutrosophic Matrices > Neutrosophic logic toolbox Package_ Neutrosophic Matrices/@term/sort.m

    function t=sort(t)
% function t=sort(t)
% arranges the elements in the term ascendingly with respect to denomitaors
%In the Name of ALLAH
% neutrosphic logic toolbox for computing single valued neutrosophic Matrice 
% Copyright (C) 2015-2019 Broumi said 
%for for details see the refrence:  
%Said Broumi, Le Hoang Son, Assia Bakali, Mohamed Talea, Florentin Smarandache,
%Ganeshsree Selvachandran, Computing Operational Matrices in Neutrosophic Environments:
%A Matlab Toolbox,Neutrosophic Sets and Systems, 18,2017,pp.58-66.
% neutrosphic logic toolbox for computing single valued neutrosophic Matrice comes 
% This is free software, and you are welcome to redistribut;see license.txt for details.
if isa(t,'term')
    if length(t)>1
        
        % cheking if is sorted
        i=2;sorted=1;
        while (i<=length(t))&sorted
            if t(i-1).d > t(i).d
                sorted=0;
                i=i+1;
            elseif t(i-1).d<t(i).d
                sorted=1;
                i=i+1;
            else 
                error('wrong term, equal denumerators')
            end
        end
        
        % 
        if sorted
            t=t;
        else
            % sort the terms of the term
            % --------------------------
            while ~sorted
                sorted=1;
                for i=2:length(t)
                    if t(i-1).d>t(i).d
                        tempt=t(i-1);
                        t(i-1)=t(i);
                        t(i)=tempt;
                        sorted=0;
                    end
                end
                
            end
            
            % --------------------------
            % end of sorting the terms of the term
            
        end  
        
    else
        t=t;
    end
 
    
else
    error(' wrong input argument, not a term, could not be sorted')
    t=[];
end